<?php

namespace App\Http\Middleware;

use App\User;
use App\ZL\Library\ErrorCode;
use Closure;
use Illuminate\Support\Facades\Auth;

class CheckXcxLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $uid = $request->uid;
        if(!$uid){
//            Auth::loginUsingId(1);
            if($request->not_check!=null){
                return $next($request);
            }
            return responseZK(ErrorCode::$notSessionIdError['code'],[],ErrorCode::$notSessionIdError['msg']);
        }
        $user = User::find($uid);
        if(!$user)
            return responseZK(ErrorCode::$notSessionIdError['code'],[],ErrorCode::$notSessionIdError['msg']);
        Auth::loginUsingId($uid);
        return $next($request);
    }
}
